package com.ps.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ps.property.PageBean;
import com.ps.property.QuestionVo;
import com.ps.service.QuestionService;
import com.ps.store.QuestionStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gt
 * @类说明：
 * @date 2020/10/23 9:20
 */
@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    QuestionStore questionStore;

    @Override
    public int questionAdd(QuestionVo questionVo) {
        return questionStore.questionAdd(questionVo);
    }

    @Override
    public PageBean<QuestionVo> questionQuery(String questionTitle, int currentPage, int pageSize) {
        //设置分页信息，分别是当前页数和每页显示行数
        PageHelper.startPage(currentPage,pageSize,true);

        List<QuestionVo> list = questionStore.questionQuery(new QuestionVo("%"+questionTitle+"%"));

        //通过这个pageInfo这个对象获取到查询总条数
        PageInfo pageInfo = new PageInfo(list);
        long total = pageInfo.getTotal();

        PageBean<QuestionVo> pageBean = new PageBean<>(currentPage,pageSize,total);
        pageBean.setData(list);

        return pageBean;
    }

    @Override
    public List<QuestionVo> questionQueryByReplyAmountBigZero() {
        return questionStore.questionQueryByReplyAmountBigZero();
    }

    @Override
    public List<QuestionVo> questionQueryByReplyAmountZero() {
        return questionStore.questionQueryByReplyAmountZero();
    }

    @Override
    public QuestionVo questionQueryByQuestionId(int questionId) {
        return questionStore.questionQueryById(questionId);
    }

    @Override
    public int questionUpdate(QuestionVo questionVo) {
        return questionStore.questionUpdate(questionVo);
    }

    @Override
    public int addBrowseAmount(int questionId) {
        return questionStore.addBrowseAmount(questionId);
    }

    @Override
    public int addReplyArticleNumber(int questionId) {
        return questionStore.addReplyArticleNumber(questionId);
    }

    @Override
    public int addReplyAmount(int questionId) {
        return questionStore.addReplyAmount(questionId);
    }

    @Override
    public int addCommentAmount(int questionId) {
        return questionStore.addCommentAmount(questionId);
    }

    @Override
    public int addCollectAmount(int questionId) {
        return questionStore.addCollectAmount(questionId);
    }
}
